package Search;

import Data.GroupFriendData;

import java.sql.*;

public class SearchFriendInformationFromGroup {
    private GroupFriendData groupFriendData;
    String url = "jdbc:mysql://127.0.0.1:3306/nox?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8";
    String user = "root";
    String password = "Mi20030610.";

    public SearchFriendInformationFromGroup(GroupFriendData groupFriendData) {
        this.groupFriendData = groupFriendData;
    }

    public GroupFriendData getGroupFriendData() {
        return groupFriendData;
    }

    public void setGroupFriendData(GroupFriendData groupFriendData) {
        this.groupFriendData = groupFriendData;
    }

    public GroupFriendData searchInformation() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection Conn = DriverManager.getConnection(url, user, password);
        String sql="select *from userinformation where id=?;";
        PreparedStatement operation=Conn.prepareStatement(sql);
        operation.setString(1,groupFriendData.getId());

        ResultSet resultSet=operation.executeQuery();
        if(resultSet.next())
        {
            //设置个人信息
            groupFriendData.setEmailNumber(resultSet.getString("emailNumber"));
            groupFriendData.setSex(resultSet.getString("sex"));
            groupFriendData.setBirth(resultSet.getDate("birth"));
            groupFriendData.setSaying(resultSet.getString("saying"));
        }
        return groupFriendData;
    }
}
